from Tkinter import *
from tkSimpleDialog import *
from client import *
from project import *
from database import *

class UseCasesFrame(Frame):
    
    
    def __init__(self, parentControl,project, serverProxy):
        
        Frame.__init__(self, parentControl)
        self.parentControl = parentControl
        self.project = project
        self.serverProxy = serverProxy
        self.summary = []
        
        self.useCaseLabel = Label(parentControl, text="Nom du cas d'usage" )
        self.useCaseLabel.grid(column = 3, row = 1)
        
        
        self.listbox = Listbox(parentControl)
        self.listbox.grid(column = 2, row= 2)
        
        buttonCreate = Button(parentControl, text = "Creer un cas d'usage", command = self.createUseCase)
        buttonCreate.grid(column =2 , row = 10)
        
        
        self.useCaseDescription = Text(parentControl, width=20, height=20)
        self.useCaseDescription.grid(column=3, row=2)
        
        
        
        self.saveButton = Button(parentControl, text = "sauvegarder",command = self.save)
        self.saveButton.grid(column = 3, row=5) 
        
        
        
        
        
        
        
    def createUseCase(self):
        self.useCaseName = askstring('String', "Veuillez entrez le cas d'usage")
        if(self.useCaseName != ""):
            self.listbox.insert(END,  self.useCaseName)
            
            
   
        
        
        
    def save(self):
        newUseCase = str(self.listbox.get(self.listbox.curselection(), self.listbox.curselection()))
        self.serverProxy.createUseCase(self.project.id, newUseCase,self.useCaseDescription.__getitem__)
        
        
        

       
        
        
        
    
      
        
      
        
        
        
if __name__ == "__main__":
    root = Tk()
    client =ServerProxy()
    project = client.createProject("Foo", "Bar", "Frob")
    frame = UseCasesFrame(root,project,client)
    root.mainloop()
        